package model

import (
	"gorm.io/gorm"
	__ "videosS_rpc/basic/proto"
)

type Videos struct {
	gorm.Model
	Title        string `gorm:"type:varchar(225);commit:视频标题"`
	Introduction string `gorm:"type:varchar(225);commit:视频简介"`
	Types        int    `gorm:"type:int;commit:1剧集/2电影/3综艺/4纪录片/5动漫/6儿童"`
	Permission   int    `gorm:"type:int;commit:1免费/2VIP专享/3付费点播"`
	VideoUrl     string `gorm:"type:varchar(225);commit:视频Url"`
	VideoCover   string `gorm:"type:varchar(225);commit:视频封面"`
}

func (v *Videos) VideosShow(DB *gorm.DB, id int) (err error) {
	err = DB.Model(&v).Where("id=?", id).First(&v).Error
	return err
}

func (v *Videos) VideosAdd(DB *gorm.DB) error {
	var err error
	err = DB.Create(&v).Error
	return err
}

func (v *Videos) VideosList(DB *gorm.DB, size, page int) (list []*__.VideoList, err error) {
	offset := (page - 1) * size
	err = DB.Model(&v).Offset(offset).Limit(size).Find(&list).Error
	return list, err
}

func (v *Videos) IsVideosList(DB *gorm.DB, size, page int, title, introduction, video_url, video_cover string) (list []*__.VideoList, err error) {
	offset := (page - 1) * size
	err = DB.Model(&v).Where("title = ?", title).
		Where("introduction = ?", introduction).
		Where("video_url = ?", video_url).
		Where("video_cover = ?", video_cover).
		Offset(offset).Limit(size).Find(&list).Error
	return list, err
}
